<template>
	<view class="bgView">
		<!-- <page-head :title="title"></page-head> -->
		<!-- <mSearch :mode="2" button="outside" radius="5" @search="search($searchKey,2)"></mSearch> -->
        <uni-segmented-control v-if="dataType == 9" :current="current" :values="items" @clickItem="onClickItem" style-type="text" active-color="#6ebf9a"></uni-segmented-control>
		<view class="uni-padding-wrap uni-common-mt" v-for="(item,index) in listArray" :key="index">
			<view class="uni-card">
				<view class="uni-card-content">
					<view class="uni-card-content-inner">
						<view class="lyx-between">
							<view class="eventView">
								<view class="dotView" :style="{'background-color':taskTypeColor[item.taskType -1]}"></view>
							<view class="type">{{item.taskTypeName}}</view>
							</view>
							
							<view v-if='isShowDb'><button class="mini-btn" type="warn" size="mini" @click="updateSupervise(item)">督办</button></view>
							<view v-if="dataType == '88'"><button class="mini-btn" type="warn" size="mini" @click="removeEvent(item)">删除</button></view>
						</view>
						<view @click="showEventDetail(item)">
							<view class="eventView" v-if="dataType !== '88'">
							<text>上报时间：</text>
							<text>{{item.dateTime}}</text>
						</view>
						<view class="eventView">
							<text>标题内容：</text>
							<text>{{item.questionTitle}}</text>
						</view>
						<view class="eventView">
							<text>事件类型：</text>
							<text>{{item.questionTypeName}}</text>
						</view>
						<view class="">
							<text>事件描述：</text>
							<text>{{item.questionContent}}</text>
						</view>
						</view>
					</view>
				</view>
			</view>
		</view>

        <view v-if="listArray.length==0" class="uni-flex" style="text-align: center;color: #888888;margin-top:120upx;flex-direction: column">
            <view style="padding: 10upx;">
                <image style="width: 100upx;height: 100upx;" src="../../../static/img/ico_empty.png"></image>
            </view>
            <view style="padding: 10upx;">
                没有数据
            </view>
        </view>

	</view>
</template>

<script>
	import mSearch from "@/components/mehaotian-search/mehaotian-search.vue";
    import uniSegmentedControl from '@/components/uni-segmented-control/uni-segmented-control.vue'
    import UniTag from "../../../components/uni-tag/uni-tag";
	export default {
		components: {
          uniSegmentedControl,
          UniTag,
          mSearch
		},
		data() {
			return {
				listArray: [],
				dataType:'',
				pageNo:1,
				taskTypeColor:['#BE0005','#DE691B','#FFF9E2','#369B50'],
                items: ['我督办','被督办'],
                current: 0
			};
		},
		computed:{
			isShowDb(){
				let db = this.dataType
				let ret = false
				if(db == 7 || db == 8 || db == 3){
					ret = true
				}
				return ret
			}
		},
		onLoad(e) {
			uni.setNavigationBarTitle({
				title: e.data,
			})
			// 1:待我审批 2:待复查（废弃） 3:处置中事件，我已审批 4:上报中（废弃） 5:正常办结事件 6:超期办结事件 7:预警事件 8:超期事件 9:已督办事件 88:草稿箱
			if(e.data === '待我审批' || e.data === '待处理事件'){
				this.dataType = '1';
			}else if(e.data === '待复查事件'){
				this.dataType = '2';
			}else if(e.data === '处置中事件' || e.data === '我已审批'){
				this.dataType = '3';
			}else if(e.data === '上报中事件'){
				this.dataType = '4';
			}else if(e.data === '正常办结事件'){
				this.dataType = '5';
			}else if(e.data === '超期办结事件'){
				this.dataType = '6';
			}
			else if(e.data === '预警事件'){
				this.dataType = '7';
			}
			else if(e.data === '超期事件'){
				this.dataType = '8';
			}
			else if(e.data === '已督办事件'){
				this.dataType = '9';
			}
			else if (e.data === '草稿箱'){
				this.dataType = '88';
			 }
			// this.getList();
			
			
		},
		onShow() {
			this.pageNo = 1;
			this.listArray = new Array();
			this.getList();
		},
		onPullDownRefresh() {
			this.pageNo = 1;
			this.listArray = new Array();
			this.getList();
            uni.stopPullDownRefresh();
		},
		onReachBottom() {
			this.pageNo++;
			this.getList();
			

		},
		methods: {
            onClickItem(current){
	            this.pageNo = 1;
	            this.listArray = new Array();
                this.current = current
                this.getList()
            },
			getList() {
				var url = '';
				if(this.dataType !== '88'){
					url = 'ac/xagrid/appEventServiceImpl/getEventList';
				}else{
					url = 'ac/xagrid/appEventServiceImpl/getDraftsList';
				}
				let map = {pageNo:this.pageNo,pageSize:'10',type:this.dataType}
				if(this.dataType == 9) {
					map.supervise_status = this.current == 1 ?'1':'2'
                }
				this.$http.get(url,map).then((res)=>{
					console.log(res.data);
					this.listArray = this.listArray.concat(res.data.results);
				})
				
			},
			showEventDetail: function(item) {
				if(this.dataType === '88'){
					uni.navigateTo({
						url:'../eventReport/eventReport?id='+item.id+'&btn=3',
					})
				}else if(this.dataType === '6'){
					uni.navigateTo({
						url: "../eventDetail/eventDetail?id=" + item.eventId
					})
				}else{
                    uni.navigateTo({
                        url: "../eventDetail/eventDetail?id=" + item.eventId + '&type='+this.dataType
                    })
                }
				
			},
			gofeedback(e) {
				console.log(this.list[e].eventTitle);
				uni.navigateTo({
					url: '../../mine/updatePassword/updatePassword?data=' + this.list[e].eventTitle
				})

			},
			updateSupervise(info){
				let url = 'ac/xagrid/appEventServiceImpl/updateSupervise'
				this.$http.get(url,{event_id:info.eventId}).then((data)=>{
					console.log(data,'返回来的信息')
					if(data.errcode == '0') {
						uni.showToast({
							title:'督办成功'
						})
					}else{
						uni.showToast({
							title:data.errmsg
						})
					}
				})
			},
          removeEvent(info){
	          let url = 'ac/xagrid/appEventServiceImpl/remove'
	          this.$http.get(url,{id:info.eventId}).then((data)=>{
		          console.log(data,'返回来的信息')
		          if(data.errcode == '0') {
			          uni.showToast({
				          title:'删除成功'
			          })
                      this.pageNo = 1;
                      this.listArray = new Array();
                      this.getList();
		          }else{
			          uni.showToast({
				          title:data.errmsg
			          })
		          }
	          })
          }
		}
	}
</script>

<style>
	.bgView {
		width: 100%;
		height: 100%;
	}

	.uni-list-cell {
		margin: 30upx;
		border-radius: 10;
		box-shadow: 0 0 5upx 5upx #D9D9D9;
	}

	.uni-list-cell-navigate {
		flex-direction: column;
		display: flex;
		align-items: flex-start;
		justify-content: flex-start;
	}

	.dotView {
		width: 20upx;
		height: 20upx;
		border-radius: 10upx;
		background-color: #0FAEFF;
	}

	.eventView {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
	}
	.lyx-between{
		display: flex;
		justify-content: space-between;
	}

	.type {
		margin-left: 10upx;
	}
	button {
		margin-top: 30upx;
		margin-bottom: 30upx;
	}

	.button-sp-area {
		margin: 0 auto;
		width: 60%;
	}

	.mini-btn {
		margin-right: 10upx;
	}
</style>
